#include "CircleEntity.h"
#include <TGS/GeoMath2.0/Envelope.h>
#include <TGS/MapControl2.0/RenderContext.h>
#include <QPainter>


CircleEntity::CircleEntity(void)
	: _radius(0)
{
}


CircleEntity::~CircleEntity(void)
{
}

TGS::GeoMath::Envelope CircleEntity::getEnvelope() const
{
	if(!isSpaceModel()) return Envelope();
	if(0 == _radius) return Envelope();

	Point right(_center.getX() + _radius, _center.getY());
	Point left(_center.getX() - _radius, _center.getY());
	Point top(_center.getX(), _center.getY() + _radius);
	Point down(_center.getX(), _center.getY() - _radius);

	Envelope envelope;
	envelope.expandToInclude(right);
	envelope.expandToInclude(left);
	envelope.expandToInclude(top);
	envelope.expandToInclude(down);

	return envelope;
}

void CircleEntity::render( RenderContext* renderContext )
{
	renderContext->painter()->save();

	QPoint center = renderContext->mapToPixel().mapToScreen(_center);
	int radiusInPix = _radius / renderContext->mapToPixel().mapUnitsPerPixel();

	QPen pen(QBrush(getColor()), getWidth());
	renderContext->painter()->setPen(pen);
	renderContext->painter()->drawEllipse(center, radiusInPix, radiusInPix);

	renderContext->painter()->restore();
}

void CircleEntity::traslate( const Point& point )
{
	_center.setX(_center.getX() + point.getX());
	_center.setY(_center.getY() + point.getY());
}
